﻿using System;
using BingoServerCommon.Log4net;
using Dapper;
using MySql.Data.MySqlClient;

namespace BingoHallServerConsole.Helper.Exp
{
	public class ExpHelper
	{
		/// <summary>
		/// 给用户增加经验值 
		/// </summary>
		/// <param name="playerId"></param>
		/// <param name="exp">int，可以为负</param>
		/// <returns></returns>
		public static bool AddExp(int playerId, int exp)
		{
			try
			{
				MySqlConnection conn = Program.ConnectionPool.getConnection(); //从连接池拿到一个连接
				var sql = $"UPDATE players p set p.exp = p.exp + ({exp}) WHERE p.id = {playerId}";
				var count = conn.Execute(sql);
				return count == 1;
			}
			catch (Exception e)
			{
				LogHelper.WriteError("ExpHelper.AddExp失败", e);
				return false;
			}
		}
	}
}
